package com.its.web;

import com.its.pojo.User;
import com.its.service.UserService;
import com.its.util.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 朱厚强
 * @since 2024年01月08日
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户api")
public class UserController {
    @Autowired
    private UserService userService;
    /**
     * 登录认证
     * @param user
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user,HttpServletRequest request){
        String addr = request.getRemoteAddr();
        System.out.println("UserController:addr:"+addr);
        return userService.login(user,addr);
    }

    /**
     *  获取用户信息
     */
    @GetMapping("/getUser")
    public Result queryUser(HttpServletRequest request){
        return userService.queryUserInfo(request);
    }
}
